/**********************************************************************************************
Do-file:		Specifications.do
Date:			4/5/24
Author:			Stephanie Karol
Description:	This file enables replication of "Effects of COVID-19 on the Nonprofit Sector," including production of estimates used in Tables 1 - 3 and Figures 2 - 8, as well as Appendix Tables C.1 - C.3, D.1 - D.8 and Figures A.1, B.1, C.1 - C.3.

Data for figures are output to CSV.  Finally, the do file will call two other do-files (PretrendData.do and ThreeYearHorizon.do) which produce additional results. After running,  call an R script (all-figures.R) to produce the figures. Prior to running that script, enter path to working directory at the top of the R file. The path to the same working directory must also be set at the top of this file.

***********************************************************************************************/


clear 
set more off

cd "Replication"

use "cleaned-990.dta", clear

/*Clean data*/
* Contribcurrent in the raw data includes all contributions, regardless of source
* We are interested in looking at private contributions separately from government grants
* This line nets out government grants from total contributions
replace contribcurrent = contribcurrent - govgrantsrev

/*Data cleaning: drop non-501c3 exempt orgs and observations that seem incorrect*/
* in some cases government grants > private contributions
drop if contribcurrent < 0
* drop non-501c3
keep if exempt501c3 == "501c3"

/*merge in additional data: CPI, population, COVID case data, NTEE codes, PPP data */
* fisyrendmo = yyyy-mm
gen fisyrendmo = substr(endyear,1,7)
gen year = fisyr

merge m:1 fisyrendmo using "cpifisyr.dta", keep(1 3)
drop year _merge

merge m:1 state fisyr using "censuspop.dta"
drop _merge
 
merge m:1 filingmonth fips using "FootTraffic-Clean.dta"
drop if _merge == 2
drop _merge

replace cum_workplaces = 0 if cum_workplaces == .
replace cum_transit_stations = 0 if cum_transit_stations == .
replace cum_retail_rec = 0 if cum_retail_rec == .

merge m:1 ein using "ntee.dta", keep(1 3)
drop _merge
encode ntmaj5, generate(ntee5)
replace ntee5 = . if ntmaj5 == ""

replace ntee5 = 1 if ntmaj5 == "AR"
replace ntee5 = 2 if ntmaj5 == "ED"
replace ntee5 = 3 if ntmaj5 == "HE"
replace ntee5 = 4 if ntmaj5 == "HU"
replace ntee5 = 5 if ntmaj5 == "OT"
replace ntee5 = . if ntmaj5 == ""

gen ntar = (ntmaj5 == "AR")
gen nted = (ntmaj5 == "ED")
gen nthe = (ntmaj5 == "HE")
gen nthu = (ntmaj5 == "HU")
gen ntot = (ntmaj5 == "OT")

merge 1:1 ein fisyr using "matched-f990-ppp.dta", keep(1 3)
drop _merge

* transform the data using: inverse hyperbolic sine, log, and indicators for strictly positive values. first deflate financial variables.

foreach var of varlist totalrevcurrent totalprogservexp totfundexp contribcurrent totalassetsbegyear salariescurrent govgrantsrev {
	replace `var' = `var'/(cpiu12mma/100)
}

foreach var of varlist totalrevcurrent totalprogservexp totfundexp contribcurrent  salariescurrent totalassetsbegyear totemployee pop govgrantsrev {
	gen log`var' = ln(`var')
	gen prob`var' = (`var' > 0)
	gen ihs`var' = ln(`var'+sqrt(`var'^2+1))	
}


gen after = (substr(endyear,1,4)=="2020" |substr(endyear,1,4)=="2021")
* add in December 2019 to the post-period, to include December filers in control group
replace after = 1 if ((fisyr == 2019) & (filingmonth == "12"))

/*variables capturing any exposure to COVID vs. share of months (out of 12) of exposure. */
gen anyexposure = ((filingmonth != "12") & (filingmonth != "01") & (filingmonth != "02"))

gen junefilers = (filingmonth == "06")
replace junefilers = . if ((junefilers == 0) & (filingmonth != "12") & (filingmonth != "01") & (filingmonth != "02"))

gen anyafter = anyexposure*after
gen juneafter = junefilers*after

gen feetafter = cum_retail_rec*after


/*generate individual treatment groups, and interactions between each treatment group and after */
gen fymar = (filingmonth == "03")
gen fyapr = (filingmonth == "04")
gen fymay = (filingmonth == "05")
gen fyjun = (filingmonth == "06")
gen fyjul = (filingmonth == "07")
gen fyaug = (filingmonth == "08")
gen fysep = (filingmonth == "09")
gen fyoct = (filingmonth == "10")
gen fynov = (filingmonth == "11")

foreach var of varlist fy* {
    gen `var'after = `var'*after
}

* renaming some variables to keep the names short and legal
rename contribcurrent contribcur
rename totalprogservexp pse
rename totfundexp fund
rename salariescurrent salcur
rename totemployee totemp
rename govgrantsrev ggr
rename totalrevcurrent trc

rename logcontribcurrent logcontribcur
rename logtotalprogservexp logpse
rename logtotfundexp logfund
rename logsalariescurrent logsalcur
rename logtotemployee logtotemp
rename loggovgrantsrev logggr
rename logtotalrevcurrent logtrc

rename probcontribcurrent probcontribcur
rename probtotalprogservexp probpse
rename probtotfundexp probfund
rename probsalariescurrent probsalcur
rename probtotemployee probtotemp
rename probgovgrantsrev probggr
rename probtotalrevcurrent probtrc

rename ihscontribcurrent ihscontribcur
rename ihstotalprogservexp ihspse
rename ihstotfundexp ihsfund
rename ihssalariescurrent ihssalcur
rename ihstotemployee ihstotemp
rename ihsgovgrantsrev ihsggr
rename ihstotalrevcurrent ihstrc

xtset ein fisyr

/*Binary DDs, with and without controls;
one horizon at a time
(dropping variable anyexposure because it should be picked up by the fixed effects)

These results are used to produce Figures 3 and A.1, as well as Table D.1
 */
foreach var of varlist contribcur pse fund salcur totemp ggr trc {
reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2019), a(ein) vce(cluster fips) 
est sto any`var'19 

reghdfe ihs`var' anyafter after ihspop ihstotalassetsbegyear if (fisyr == 2018 | fisyr == 2019), a(ein fips ntee5) vce(cluster fips)
est sto any`var'19_control
}

foreach var of varlist contribcur pse fund salcur totemp ggr trc {
reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2020), a(ein) vce(cluster fips) 
est sto any`var'20 

reghdfe ihs`var' anyafter after ihspop ihstotalassetsbegyear if (fisyr == 2018 | fisyr == 2020), a(ein fips ntee5) vce(cluster fips)
est sto any`var'20_control
}

mat fig3_19 = J(7,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
		qui est restore any`var'19
		mat fig3_19[`i',1]= e(b)[1,1]
		mat fig3_19[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
}

preserve
svmat fig3_19
rename fig3_191 fig3_19b
rename fig3_192 fig3_19se
keep fig3_19*
drop if _n > 7
export delimited using "fig3_19.csv", replace
restore

mat fig3_20 = J(7,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
		qui est restore any`var'20
		mat fig3_20[`i',1]= e(b)[1,1]
		mat fig3_20[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
}

preserve
svmat fig3_20
rename fig3_201 fig3_20b
rename fig3_202 fig3_20se
keep fig3_20*
drop if _n > 7
export delimited using "fig3_20.csv", replace
restore

* for Appendix Tables D.2 through D.5, binary DDs: intensive/extensive for contributions, pse, ggr

foreach var of varlist contribcur pse totemp salcur ggr {
reghdfe log`var' anyafter after if (fisyr == 2018 | fisyr == 2019), a(ein) vce(cluster fips) 
est sto any`var'19_i

reghdfe prob`var' anyafter after if (fisyr == 2018 | fisyr == 2019), a(ein) vce(cluster fips) 
est sto any`var'19_e 

reghdfe log`var' anyafter after logpop logtotalassetsbegyear if (fisyr == 2018 | fisyr == 2019), a(ein fips ntee5) vce(cluster fips) 
est sto any`var'19_i_control

reghdfe prob`var' anyafter after logpop logtotalassetsbegyear if (fisyr == 2018 | fisyr == 2019), a(ein fips ntee5) vce(cluster fips) 
est sto any`var'19_e_control
}

foreach var of varlist contribcur totemp salcur pse ggr {
reghdfe log`var' anyafter after if (fisyr == 2018 | fisyr == 2020), a(ein) vce(cluster fips) 
est sto any`var'20_i

reghdfe prob`var' anyafter after if (fisyr == 2018 | fisyr == 2020), a(ein) vce(cluster fips) 
est sto any`var'20_e 

reghdfe log`var' anyafter after logpop logtotalassetsbegyear if (fisyr == 2018 | fisyr == 2020), a(ein fips ntee5) vce(cluster fips) 
est sto any`var'20_i_control

reghdfe prob`var' anyafter after logpop logtotalassetsbegyear if (fisyr == 2018 | fisyr == 2020), a(ein fips ntee5) vce(cluster fips) 
est sto any`var'20_e_control
}


/*Figure 5: binary DDs within major categories */

foreach var of varlist contribcur pse fund trc salcur totemp ggr {
	foreach var2 of varlist ntar nted nthe nthu ntot {
		reghdfe ihs`var' anyafter after if (`var2'==1 & (fisyr == 2018 | fisyr == 2019)), a(ein) vce(cluster fips)
est sto any`var'_`var2'19

		reghdfe ihs`var' anyafter after if (`var2'==1 & (fisyr == 2018 | fisyr == 2020)), a(ein) vce(cluster fips)
est sto any`var'_`var2'20
	}
}

/*The following outputs results to a CSV; figures are produced using R.*/
mat anyout19 = J(35,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
	foreach var2 of varlist ntar nted nthe nthu ntot {
		qui est restore any`var'_`var2'19
		mat anyout19[`i',1]= e(b)[1,1]
		mat anyout19[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
	}
}

preserve
svmat anyout19
rename anyout191 anyout19b
rename anyout192 anyout19se
keep anyout19*
drop if _n > 35
export delimited using "forgraphsbycategory19.csv", replace
restore

mat anyout20 = J(35,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
	foreach var2 of varlist ntar nted nthe nthu ntot {
		qui est restore any`var'_`var2'20
		mat anyout20[`i',1]= e(b)[1,1]
		mat anyout20[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
	}
}

preserve
svmat anyout20
rename anyout201 anyout20b
rename anyout202 anyout20se
keep anyout20*
drop if _n > 35
export delimited using "forgraphsbycategory20.csv", replace
restore

/*Figure 4: pairwise binary DDs based on filing month */
mat att_filingmonth19 = J(63,2,.)
mat att_filingmonth19_i = J(63,2,.)
mat att_filingmonth19_e = J(63,2,.)

mat att_filingmonth20 = J(63,2,.)
mat att_filingmonth20_i = J(63,2,.)
mat att_filingmonth20_e = J(63,2,.)

local i = 1
foreach var1 of varlist fymar fyapr fymay fyjun fyjul fyaug fysep fyoct fynov {
    foreach var2 of varlist contribcur fund trc pse salcur totemp ggr {
	    reghdfe ihs`var2' `var1'after after if (`var1' == 1 | anyexposure == 0 & (fisyr == 2018 | fisyr == 2019)), a(ein) vce(cluster fips)
		mat att_filingmonth19[`i',1] = e(b)[1,1]
		mat att_filingmonth19[`i',2] = sqrt(e(V)[1,1])
		
		reghdfe ihs`var2' `var1'after after if (`var1' == 1 | anyexposure == 0 & (fisyr == 2018 | fisyr == 2020)), a(ein) vce(cluster fips)
		mat att_filingmonth20[`i',1] = e(b)[1,1]
		mat att_filingmonth20[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
	}
}

preserve
svmat att_filingmonth19
rename att_filingmonth191 att_filingmonth19b
rename att_filingmonth192 att_filingmonth19se
keep att_filingmonth*
drop if _n > 63
export delimited using "att_filingmonth19.csv", replace
restore

preserve
svmat att_filingmonth20
rename att_filingmonth201 att_filingmonth20b
rename att_filingmonth202 att_filingmonth20se
keep att_filingmonth*
drop if _n > 63
export delimited using "att_filingmonth20.csv", replace
restore

/*Figure B.1: DD, cumulative change in foot traffic */

gen nonstandard = (ein == 10228297 | ein ==  411391001 | ein ==  541733690 | ein ==  740960070 | ein ==  842764564 | ein ==  910568708)

mat att_contribcur_feet = J(51,2,.)
mat att_pse_feet = J(51,2,.)
mat att_fund_feet = J(51,2,.)
mat att_trc_feet = J(51,2,.)
mat att_salcur_feet = J(51,2,.)
mat att_totemp_feet = J(51,2,.)
mat att_ggr_feet = J(51,2,.)

local i = 1

levelsof fips, local(states)
foreach state of local states {
    foreach var of varlist contribcur pse salcur totemp ggr {
	    di `state'
		reghdfe ihs`var' feetafter after if ((fisyr == 2018 | fisyr == 2019) & (nonstandard == 0) & (fips == `state') & (junefilers == 1 | anyexposure == 0)), a(ein) vce(robust) /*here robust makes sense because clustering within a state if you're running one state at a time is just robustness. */
		mat att_`var'_feet[`i',1]=e(b)[1,1]
		mat att_`var'_feet[`i',2]=sqrt(e(V)[1,1])
	}
	local i = `i'+1
}

local basepath = "att_"
local suffix = "_feet.csv"
foreach var of varlist contribcur pse salcur totemp ggr {
preserve
svmat att_`var'_feet
rename att_`var'_feet1 att_`var'_feetb
rename att_`var'_feet2 att_`var'_feetse
keep att_`var'_feet*
drop if _n > 51
export delimited using `basepath'`var'`suffix', replace
restore
}


label variable anyafter "Any Exposure $\cdot$ After"
label variable juneafter "June Filers $\cdot$ After"
label variable fyjunafter "June Filers $\cdot$ After"
label variable anyexposure "Any Exposure"
label variable junefilers "June Filers"
label variable fyjun "June Filers"
label variable after "After"
label variable ihspop "State Population"
label variable ihstotalassetsbegyear "Charity Assets"

label variable ntar "Arts"
label variable nted "Education"
label variable nthe "Health"
label variable nthu "Human Services"
label variable ntot "Other"

/*Tables D.6 and D.7: Civil Rights specs */
gen civilrights = (substr(nteecc,1,1)=="R")
sum civilrights

foreach var of varlist contribcur pse salcur totemp ggr {
	reghdfe ihs`var' c.anyafter#i.civilrights c.after#i.civilrights if (fisyr == 2018 | fisyr == 2019), a(ein) vce(cluster fips) 
est sto any`var'_indicrights19

reghdfe ihs`var' c.anyafter#i.civilrights c.after#i.civilrights if (fisyr == 2018 | fisyr == 2020), a(ein) vce(cluster fips) 
est sto any`var'_indicrights20
}

foreach var of varlist contribcur pse salcur totemp ggr {
	reghdfe ihs`var' anyafter after if ((fisyr == 2018 | fisyr == 2019) & (civilrights==1)), a(ein) vce(cluster fips) 
est sto any`var'_rights191

reghdfe ihs`var' anyafter after if ((fisyr == 2018 | fisyr == 2020) & (civilrights==1)), a(ein) vce(cluster fips) 
est sto any`var'_rights201
}

foreach var of varlist contribcur pse salcur totemp ggr {
	reghdfe ihs`var' anyafter after if ((fisyr == 2018 | fisyr == 2019) & (civilrights==0)), a(ein) vce(cluster fips) 
est sto any`var'_rights190

reghdfe ihs`var' anyafter after if ((fisyr == 2018 | fisyr == 2020) & (civilrights==0)), a(ein) vce(cluster fips) 
est sto any`var'_rights200
}

mat define testparms19 = J(2,5,.)

est restore anycontribcur_indicrights19 
testparm i.civilrights#c.anyafter, equal
mat testparms19[1,1]=r(F)
mat testparms19[2,1]=r(p)

est restore anypse_indicrights19
testparm i.civilrights#c.anyafter, equal
mat testparms19[1,5]=r(F)
mat testparms19[2,5]=r(p)

mat define testparms20 = J(2,5,.)

est restore anycontribcur_indicrights20 
testparm i.civilrights#c.anyafter, equal
mat testparms20[1,1]=r(F)
mat testparms20[2,1]=r(p)

est restore anypse_indicrights20
testparm i.civilrights#c.anyafter, equal
mat testparms20[1,5]=r(F)
mat testparms20[2,5]=r(p)


est restore anysalcur_indicrights19
testparm i.civilrights#c.anyafter, equal
mat testparms19[1,4]=r(F)
mat testparms19[2,4]=r(p)

est restore anysalcur_indicrights20
testparm i.civilrights#c.anyafter, equal
mat testparms20[1,4]=r(F)
mat testparms20[2,4]=r(p)

est restore anytotemp_indicrights19
testparm i.civilrights#c.anyafter, equal
mat testparms19[1,3]=r(F)
mat testparms19[2,3]=r(p)

est restore anytotemp_indicrights20
testparm i.civilrights#c.anyafter, equal
mat testparms20[1,3]=r(F)
mat testparms20[2,3]=r(p)

est restore anyggr_indicrights19
testparm i.civilrights#c.anyafter, equal
mat testparms19[1,2]=r(F)
mat testparms19[2,2]=r(p)

est restore anyggr_indicrights20
testparm i.civilrights#c.anyafter, equal
mat testparms20[1,2]=r(F)
mat testparms20[2,2]=r(p)

matrix rownames testparms19 = \textit{F} \textit{p>F}
matrix colnames testparms19 = \phantom{a} \phantom{a} \phantom{a} \phantom{a} \phantom{a} 

matrix rownames testparms20 = \textit{F} \textit{p>F}
matrix colnames testparms20 = \phantom{a} \phantom{a} \phantom{a} \phantom{a} \phantom{a} 

label variable anyafter "\$\beta\_1$"

esttab anycontribcur_rights190 anyggr_rights190 anytotemp_rights190 anysalcur_rights190 anypse_rights190 using "apptablepanela19.tex", not se tex replace fragment label r2 nomtitles b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) nolines nonumbers substitute(\_ _ "[1em]" "") eqlabels(none)

esttab anycontribcur_rights191 anyggr_rights191 anytotemp_rights191 anysalcur_rights191 anypse_rights191 using "apptablepanelb19.tex", not se tex replace fragment label r2 nomtitles b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) nolines nonumbers substitute(\_ _ "[1em]" "") eqlabels(none)

esttab matrix(testparms19,fmt(%20.3f)) using "apptablepanelc19.tex", replace tex nolines fragment mlabels(none) substitute(> \$>\$)

esttab anycontribcur_rights200 anyggr_rights200 anytotemp_rights200 anysalcur_rights200 anypse_rights200 using "apptablepanela20.tex", not se tex replace fragment label r2 nomtitles b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) nolines nonumbers substitute(\_ _ "[1em]" "") eqlabels(none)

esttab anycontribcur_rights201 anyggr_rights201 anytotemp_rights201 anysalcur_rights201 anypse_rights201 using "apptablepanelb20.tex", not se tex replace fragment label r2 nomtitles b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) nolines nonumbers substitute(\_ _ "[1em]" "") eqlabels(none)

esttab matrix(testparms20,fmt(%20.3f)) using "apptablepanelc20.tex", replace tex nolines fragment mlabels(none) substitute(> \$>\$)

/*Tables 2 and 3: Heterogeneity by Size*/
* define quintiles of asset size
egen meantotass = mean(totalassetsbegyear) if fisyr == 2018, by(ein)

sum meantotass, d

gen tempassbin1 = .
gen tempassbin2 = .
gen tempassbin3 = .
gen tempassbin4 = .
gen tempassbin5 = .

_pctile meantotass if fisyr == 2018, percentiles(20(20)80)

replace tempassbin1 = 1 if (meantotass <= r(r1) & (fisyr == 2018))
replace tempassbin2 = 1 if ((meantotass > r(r1)) & (meantotass <= r(r2)) & (fisyr == 2018))
replace tempassbin3 = 1 if ((meantotass > r(r2)) & (meantotass <= r(r3)) & (fisyr == 2018))
replace tempassbin4 = 1 if ((meantotass > r(r3)) & (meantotass <= r(r4)) & (fisyr == 2018))
replace tempassbin5 = 1 if (meantotass > r(r4) & (fisyr == 2018))
foreach var of varlist tempassbin* {
	replace `var' = 0 if `var' == . & fisyr == 2018
}	

forvalues i = 1(1)5 {
	egen assbin`i' = max(tempassbin`i'), by(ein)
}

drop tempassbin*

foreach var of varlist contribcur pse fund salcur totemp ggr {
 forvalues i = 1(1)5 {
reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2019) & (assbin`i'==1), a(ein) vce(cluster fips) 
est sto any`var'19_q`i' 


reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2020) & (assbin`i'==1), a(ein) vce(cluster fips) 
est sto any`var'20_q`i'  
}
}

* the below is useful for tests of = coefs
mat define topbottomtest19 = J(5,2,.)
mat define topbottomtest20 = J(5,2,.)

local i = 1
foreach var of varlist contribcur ggr salcur totemp pse {
reghdfe ihs`var' i.assbin5#c.anyafter i.assbin5#after if (fisyr == 2018 | fisyr == 2019) & (assbin1==1 | assbin5 == 1), a(ein) vce(cluster fips) 
est sto any`var'19_qs15 
test _b[0b.assbin5#c.anyafter]=_b[1.assbin5#c.anyafter]
mat topbottomtest19[`i',1]= r(F)
mat topbottomtest19[`i',2]= r(p)

reghdfe ihs`var' i.assbin5#c.anyafter i.assbin5#after if (fisyr == 2018 | fisyr == 2020) & (assbin1==1 | assbin5 == 1), a(ein) vce(cluster fips) 
est sto any`var'20_qs15 
test _b[0b.assbin5#c.anyafter]=_b[1.assbin5#c.anyafter]
mat topbottomtest20[`i',1]= r(F)
mat topbottomtest20[`i',2]= r(p)

local i = `i' + 1
}

esttab anycontribcur19_q1 anyggr19_q1 anytotemp19_q1 anysalcur19_q1 anypse19_q1 using "q1_2019.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_q2 anyggr19_q2 anytotemp19_q2 anysalcur19_q2 anypse19_q2 using "q2_2019.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_q3 anyggr19_q3 anytotemp19_q3 anysalcur19_q3 anypse19_q3 using "q3_2019.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_q4 anyggr19_q4 anytotemp19_q4 anysalcur19_q4 anypse19_q4 using "q4_2019.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_q5 anyggr19_q5 anytotemp19_q5 anysalcur19_q5 anypse19_q5 using "q5_2019.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_q1 anyggr20_q1 anytotemp20_q1 anysalcur20_q1 anypse20_q1 using "q1_2020.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_q2 anyggr20_q2 anytotemp20_q2 anysalcur20_q2 anypse20_q2 using "q2_2020.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_q3 anyggr20_q3 anytotemp20_q3 anysalcur20_q3 anypse20_q3 using "q3_2020.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_q4 anyggr20_q4 anytotemp20_q4 anysalcur20_q4 anypse20_q4 using "q4_2020.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_q5 anyggr20_q5 anytotemp20_q5 anysalcur20_q5 anypse20_q5 using "q5_2020.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

matrix colnames topbottomtest19 = \textit{F} \textit{p>F}
matrix rownames topbottomtest19 = \phantom{a} \phantom{a} \phantom{a} \phantom{a} \phantom{a}

matrix colnames topbottomtest20 = \textit{F} \textit{p>F}
matrix rownames topbottomtest20 = \phantom{a} \phantom{a} \phantom{a} \phantom{a} \phantom{a} 

* Table D.8
esttab matrix(topbottomtest19,fmt(%20.3f)) using "topbottomtest19.tex", replace tex nolines fragment mlabels(none) substitute(> \$>\$)

esttab matrix(topbottomtest20,fmt(%20.3f)) using "topbottomtest20.tex", replace tex nolines fragment mlabels(none) substitute(> \$>\$)

label variable anyafter "Any Exposure $\cdot$ After"

* This is a table analogue to Figure 3: binary DD, no controls
esttab anycontribcur19 anyggr19 anytotemp19 anysalcur19 anypse19 using "binarydd19-nocontrols.tex", not se tex replace fragment label r2 mtitles("\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}" "Employees" "Salaries" "\shortstack{Program\\Services}") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)

esttab anycontribcur20 anyggr20 anytotemp20 anysalcur20 anypse20 using "binarydd20-nocontrols.tex", not se tex replace fragment label r2 mtitles("\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}" "Employees" "Salaries" "\shortstack{Program\\Services}") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)

* Output for Tables D.2 - D.5

esttab anypse19_i anycontribcur19_i anyggr19_i anypse20_i anycontribcur20_i anyggr20_i using "binarydd-i-nocontrols.tex", not se tex replace fragment label r2 mtitles("\shortstack{Program\\Services}" "\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}" "\shortstack{Program\\Services}" "\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after) keep(anyafter after)

esttab anypse19_e anycontribcur19_e anyggr19_e anypse20_e anycontribcur20_e anyggr20_e using "binarydd-e-nocontrols.tex", not se tex replace fragment label r2 mtitles("\shortstack{Program\\Services}" "\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}" "\shortstack{Program\\Services}" "\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)  keep(anyafter after)

esttab anytotemp19_e anysalcur19_e using "binarydd19-empsal_e.tex", not se tex replace fragment label r2 mtitles("Employees" "Salaries") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)

esttab anytotemp20_e anysalcur20_e using "binarydd20-empsal_e.tex", not se tex replace fragment label r2 mtitles("Employees" "Salaries") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)

esttab anytotemp19_i anysalcur19_i using "binarydd19-empsal_i.tex", not se tex replace fragment label r2 mtitles("Employees" "Salaries") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)

esttab anytotemp20_i anysalcur20_i using "binarydd20-empsal_i.tex", not se tex replace fragment label r2 mtitles("Employees" "Salaries") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)


* Table version of Figure A.1
esttab anyfund19 anytrc19 using "binarydd19-fundrev-nocontrols.tex", not se tex replace fragment label r2 mtitles("Fundraising" "Revenue") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)

esttab anyfund20 anytrc20 using "binarydd20-fundrev-nocontrols.tex", not se tex replace fragment label r2 mtitles("Fundraising" "Revenue") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)


* Output for Table D.1
esttab anycontribcur19_control anyggr19_control anytotemp19_control anysalcur19_control anypse19_control using "binarydd19-withcontrols.tex", not se tex replace fragment label r2 b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after) keep(anyafter after) nomtitles nonumbers nolines

esttab anycontribcur20_control anyggr20_control anytotemp20_control anysalcur20_control anypse20_control using "binarydd20-withcontrols.tex", not se tex replace fragment label r2 b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after) keep(anyafter after) nomtitles nonumbers nolines

est drop _all

gen tempeligible = (totemp <=500) if fisyr == 2018
egen eligible = max(tempeligible), by(ein)
drop tempeligible

* Results for Figure C.1
foreach var of varlist contribcur pse fund salcur totemp ggr fund trc {
reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2019) & amtapproved == ., a(ein) vce(cluster fips) 
est sto any`var'19_noppp 

reghdfe ihs`var' anyafter after ihspop ihstotalassetsbegyear if (fisyr == 2018 | fisyr == 2019) & amtapproved == ., a(ein fips ntee5) vce(cluster fips)
est sto any`var'19_noppp_ctl

}

foreach var of varlist contribcur pse fund salcur totemp ggr fund trc {
reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2020) & amtapproved == ., a(ein) vce(cluster fips) 
est sto any`var'20_noppp

reghdfe ihs`var' anyafter after ihspop ihstotalassetsbegyear if (fisyr == 2018 | fisyr == 2020) & amtapproved == ., a(ein fips ntee5) vce(cluster fips)
est sto any`var'20_noppp_ctl

}

mat figc1_19 = J(7,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
		qui est restore any`var'19_noppp
		mat figc1_19[`i',1]= e(b)[1,1]
		mat figc1_19[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
}

preserve
svmat figc1_19
rename figc1_191 figc1_19b
rename figc1_192 figc1_19se
keep figc1_19*
drop if _n > 7
export delimited using "figc1_19.csv", replace
restore

mat figc1_20 = J(7,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
		qui est restore any`var'20_noppp
		mat figc1_20[`i',1]= e(b)[1,1]
		mat figc1_20[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
}

preserve
svmat figc1_20
rename figc1_201 figc1_20b
rename figc1_202 figc1_20se
keep figc1_20*
drop if _n > 7
export delimited using "figc1_20.csv", replace
restore


* Results for Figure C.3
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
	foreach var2 of varlist ntar nted nthe nthu ntot {
		reghdfe ihs`var' anyafter after if (`var2'==1 & (fisyr == 2018 | fisyr == 2019)) & amtapproved == ., a(ein) vce(cluster fips)
est sto any`var'_`var2'19_noppp

		reghdfe ihs`var' anyafter after if (`var2'==1 & (fisyr == 2018 | fisyr == 2020)) & amtapproved == ., a(ein) vce(cluster fips)
est sto any`var'_`var2'20_noppp
	}
}

mat anyout_noppp19 = J(35,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
	foreach var2 of varlist ntar nted nthe nthu ntot {
		qui est restore any`var'_`var2'19_noppp
		mat anyout_noppp19[`i',1]= e(b)[1,1]
		mat anyout_noppp19[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
	}
}

preserve
svmat anyout_noppp19
rename anyout_noppp191 anyout_noppp19b
rename anyout_noppp192 anyout_noppp19se
keep anyout_noppp19*
drop if _n > 35
export delimited using "forgraphsbycategory19_noppp.csv", replace
restore

mat anyout_noppp20 = J(35,2,.)

local i = 1
foreach var of varlist contribcur pse fund trc salcur totemp ggr {
	foreach var2 of varlist ntar nted nthe nthu ntot {
		qui est restore any`var'_`var2'20_noppp
		mat anyout_noppp20[`i',1]= e(b)[1,1]
		mat anyout_noppp20[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
	}
}

preserve
svmat anyout_noppp20
rename anyout_noppp201 anyout_noppp20b
rename anyout_noppp202 anyout_noppp20se
keep anyout_noppp20*
drop if _n > 35
export delimited using "forgraphsbycategory20_noppp.csv", replace
restore

* Results for Figure C.2
mat att_filingmonth_noppp19 = J(63,2,.)

mat att_filingmonth_noppp20 = J(63,2,.)

local i = 1
foreach var1 of varlist fymar fyapr fymay fyjun fyjul fyaug fysep fyoct fynov {
    foreach var2 of varlist contribcur fund trc pse salcur totemp ggr {
	    reghdfe ihs`var2' `var1'after after if (`var1' == 1 | anyexposure == 0 & (fisyr == 2018 | fisyr == 2019)) & amtapproved == ., a(ein) vce(cluster fips)
		mat att_filingmonth_noppp19[`i',1] = e(b)[1,1]
		mat att_filingmonth_noppp19[`i',2] = sqrt(e(V)[1,1])
		
		reghdfe ihs`var2' `var1'after after if (`var1' == 1 | anyexposure == 0 & (fisyr == 2018 | fisyr == 2020)) & amtapproved == ., a(ein) vce(cluster fips)
		mat att_filingmonth_noppp20[`i',1] = e(b)[1,1]
		mat att_filingmonth_noppp20[`i',2] = sqrt(e(V)[1,1])
		local i = `i'+1
	}
}

preserve
svmat att_filingmonth_noppp19
rename att_filingmonth_noppp191 att_filingmonth_noppp19b
rename att_filingmonth_noppp192 att_filingmonth_noppp19se
keep att_filingmonth_noppp*
drop if _n > 63
export delimited using "att_filingmonth_noppp19.csv", replace
restore

preserve
svmat att_filingmonth_noppp20
rename att_filingmonth_noppp201 att_filingmonth_noppp20b
rename att_filingmonth_noppp202 att_filingmonth_noppp20se
keep att_filingmonth_noppp*
drop if _n > 63
export delimited using "att_filingmonth_noppp20.csv", replace
restore

* Results for Tables C.2 and C.3
* define quintiles of asset size
capture drop meantotass assbin*
egen meantotass = mean(totalassetsbegyear) if fisyr == 2018 & amtapproved == ., by(ein)

sum meantotass, d

gen tempassbin1 = .
gen tempassbin2 = .
gen tempassbin3 = .
gen tempassbin4 = .
gen tempassbin5 = .

_pctile meantotass if fisyr == 2018 & amtapproved == ., percentiles(20(20)80)

replace tempassbin1 = 1 if (meantotass <= r(r1) & (fisyr == 2018) & amtapproved == .)
replace tempassbin2 = 1 if ((meantotass > r(r1)) & (meantotass <= r(r2)) & (fisyr == 2018) & amtapproved == .)
replace tempassbin3 = 1 if ((meantotass > r(r2)) & (meantotass <= r(r3)) & (fisyr == 2018) & amtapproved == .)
replace tempassbin4 = 1 if ((meantotass > r(r3)) & (meantotass <= r(r4)) & (fisyr == 2018) & amtapproved == .)
replace tempassbin5 = 1 if (meantotass > r(r4) & (fisyr == 2018) & amtapproved == .)
foreach var of varlist tempassbin* {
	replace `var' = 0 if `var' == . & fisyr == 2018 & amtapproved == .
}	

forvalues i = 1(1)5 {
	egen assbin`i' = max(tempassbin`i') if amtapproved == ., by(ein)
}

drop tempassbin*

foreach var of varlist contribcur pse fund salcur totemp ggr {
 forvalues i = 1(1)5 {
reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2019) & (assbin`i'==1), a(ein) vce(cluster fips) 
est sto any`var'19_noppp_q`i' 


reghdfe ihs`var' anyafter after if (fisyr == 2018 | fisyr == 2020) & (assbin`i'==1), a(ein) vce(cluster fips) 
est sto any`var'20_noppp_q`i'  
}
}

* the below is useful for tests of = coefs
mat define topbottomtest_noppp19 = J(5,2,.)
mat define topbottomtest_noppp20 = J(5,2,.)

local i = 1
foreach var of varlist contribcur ggr salcur totemp pse {
reghdfe ihs`var' i.assbin5#c.anyafter i.assbin5#after if (fisyr == 2018 | fisyr == 2019) & (assbin1==1 | assbin5 == 1), a(ein) vce(cluster fips) 
est sto any`var'19_noppp_qs15 
test _b[0b.assbin5#c.anyafter]=_b[1.assbin5#c.anyafter]
mat topbottomtest_noppp19[`i',1]= r(F)
mat topbottomtest_noppp19[`i',2]= r(p)

reghdfe ihs`var' i.assbin5#c.anyafter i.assbin5#after if (fisyr == 2018 | fisyr == 2020) & (assbin1==1 | assbin5 == 1), a(ein) vce(cluster fips) 
est sto any`var'20_noppp_qs15 
test _b[0b.assbin5#c.anyafter]=_b[1.assbin5#c.anyafter]
mat topbottomtest_noppp20[`i',1]= r(F)
mat topbottomtest_noppp20[`i',2]= r(p)

local i = `i' + 1
}

esttab anycontribcur19_noppp_q1 anyggr19_noppp_q1 anytotemp19_noppp_q1 anysalcur19_noppp_q1 anypse19_noppp_q1 using "q1_2019_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_noppp_q2 anyggr19_noppp_q2 anytotemp19_noppp_q2 anysalcur19_noppp_q2 anypse19_noppp_q2 using "q2_2019_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_noppp_q3 anyggr19_noppp_q3 anytotemp19_noppp_q3 anysalcur19_noppp_q3 anypse19_noppp_q3 using "q3_2019_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_noppp_q4 anyggr19_noppp_q4 anytotemp19_noppp_q4 anysalcur19_noppp_q4 anypse19_noppp_q4 using "q4_2019_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur19_noppp_q5 anyggr19_noppp_q5 anytotemp19_noppp_q5 anysalcur19_noppp_q5 anypse19_noppp_q5 using "q5_2019_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_noppp_q1 anyggr20_noppp_q1 anytotemp20_noppp_q1 anysalcur20_noppp_q1 anypse20_noppp_q1 using "q1_2020_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_noppp_q2 anyggr20_noppp_q2 anytotemp20_noppp_q2 anysalcur20_noppp_q2 anypse20_noppp_q2 using "q2_2020_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_noppp_q3 anyggr20_noppp_q3 anytotemp20_noppp_q3 anysalcur20_noppp_q3 anypse20_noppp_q3 using "q3_2020_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_noppp_q4 anyggr20_noppp_q4 anytotemp20_noppp_q4 anysalcur20_noppp_q4 anypse20_noppp_q4 using "q4_2020_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

esttab anycontribcur20_noppp_q5 anyggr20_noppp_q5 anytotemp20_noppp_q5 anysalcur20_noppp_q5 anypse20_noppp_q5 using "q5_2020_noppp.tex", not se tex replace fragment label b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) keep(anyafter) substitute(\_ _ "[1em]" "") nomtitles nonumbers nolines

matrix colnames topbottomtest_noppp19 = \textit{F} \textit{p>F}
matrix rownames topbottomtest_noppp19 = \phantom{a} \phantom{a} \phantom{a} \phantom{a} \phantom{a}

matrix colnames topbottomtest_noppp20 = \textit{F} \textit{p>F}
matrix rownames topbottomtest_noppp20 = \phantom{a} \phantom{a} \phantom{a} \phantom{a} \phantom{a} 


esttab matrix(topbottomtest_noppp19,fmt(%20.3f)) using "topbottomtest_noppp19.tex", replace tex nolines fragment mlabels(none) substitute(> \$>\$)

esttab matrix(topbottomtest_noppp20,fmt(%20.3f)) using "topbottomtest_noppp20.tex", replace tex nolines fragment mlabels(none) substitute(> \$>\$)

/*other tables*/

* Table version of Figure C.1 
esttab anycontribcur19_noppp anyggr19_noppp anytotemp19_noppp anysalcur19_noppp anypse19_noppp using "binarydd19-nocontrols_noppp.tex", not se tex replace fragment label r2 mtitles("\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}" "Employees" "Salaries" "\shortstack{Program\\Services}") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)

esttab anycontribcur20_noppp anyggr20_noppp anytotemp20_noppp anysalcur20_noppp anypse20_noppp using "binarydd20-nocontrols_noppp.tex", not se tex replace fragment label r2 mtitles("\shortstack{Private\\Contrib.}" "\shortstack{Gov.\\Grants}" "Employees" "Salaries" "\shortstack{Program\\Services}") b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) order(anyafter after)


/*Table 1*/
egen tempeverapproved = max(amtapproved), by(ein)
* if the value is 0, and not missing, it had a match in the SBA file -- which means it did have an approval, but after our sample period.
gen everapproved = (tempeverapproved >= 0)
replace everapproved = 0 if tempeverapproved == .
drop tempeverapproved

 foreach var of varlist contribcur pse fund trc salcur totemp ggr pop totalassetsbegyear {
 	replace `var' = `var'/1000
 }
 
tabstat contribcur ggr totemp salcur pse pop totalassetsbegyear ntar nted nthe nthu ntot eligible everapproved if fisyr == 2018, by(anyexposure) statistics(mean sd) columns(statistics) format(%12.2fc) nototal longstub save

matrix transformed1 = r(Stat1)'
matrix transformed2 = r(Stat2)'

svmat transformed1
svmat transformed2

preserve

drop if _n>14
mkmat transformed11 transformed12 transformed21 transformed22, matrix(outstats)
 
restore 

matrix rownames outstats = "Private Contributions" "Government Grants" "Employment" "Salaries" "Program Services" "State Population" "Charity Assets" "\% Arts Charity" "\% Education Charity" "\% Health Charity" "\% Human Services Charity" "\% Other Charity" "\% PPP-Eligible" "\% Ever Approved"

esttab matrix(outstats,fmt(%12.2fc)) using "balancetable.tex", replace tex fragment collabels(none) mlabels(none)  nolines

* These are the observation numbers for Table 1
count if after == 0 & anyexposure == 0 & fisyr == 2018
local numdecfeb = `r(N)'
file open myfile using "numdecfeb.tex", write text replace 
file write myfile "`numdecfeb'\unskip" 
file close myfile

count if after == 0 & anyexposure == 1 & fisyr == 2018
local nummarsep = `r(N)'
file open myfile using "nummarsep.tex", write text replace 
file write myfile "`nummarsep'\unskip" 
file close myfile

* Table C.1
gen any = 1
tabstat contribcur ggr totemp salcur pse pop totalassetsbegyear ntar nted nthe nthu ntot if fisyr == 2018, by(any) statistics(mean) columns(statistics) format(%12.2fc) nototal longstub save
matrix eligtrans1 = r(Stat1)' /* all */

tabstat contribcur ggr totemp salcur pse pop totalassetsbegyear ntar nted nthe nthu ntot if fisyr == 2018, by(everapproved) statistics(mean) columns(statistics) format(%12.2fc) nototal longstub save
matrix eligtrans2 = r(Stat1)' /* no loan approval */
matrix eligtrans3 = r(Stat2)' /*ever approved*/

svmat eligtrans1
svmat eligtrans2
svmat eligtrans3


preserve

drop if _n>12
mkmat eligtrans11 eligtrans21 eligtrans31, matrix(eligtakeoutstats)
restore 

matrix rownames eligtakeoutstats = "Private Contributions" "Government Grants" "Employment" "Salaries" "Program Services" "State Population" "Charity Assets" "\% Arts Charity" "\% Education Charity" "\% Health Charity" "\% Human Services Charity" "\% Other Charity"

esttab matrix(eligtakeoutstats,fmt(%12.2fc)) using "eligtakebalancetable.tex", replace tex fragment collabels(none) mlabels(none)  nolines

* Observation numbers for Table C.1
count if after == 0 &  fisyr == 2018
local numcol1 = `r(N)'
file open myfile using "numcol1.tex", write text replace 
file write myfile "`numcol1'\unskip" 
file close myfile

count if after == 0 & everapproved == 0 & fisyr == 2018
local numcol2 = `r(N)'
file open myfile using "numcol2.tex", write text replace 
file write myfile "`numcol2'\unskip" 
file close myfile

count if after == 0 & everapproved == 1 & fisyr == 2018
local numcol3 = `r(N)'
file open myfile using "numcol3.tex", write text replace 
file write myfile "`numcol3'\unskip" 
file close myfile

/*Data for pretrends*/
do "PretrendsData.do"

/*Data for Section 6*/
do "ThreeYearHorizon.do"

/*Call R script to produce figures*/
shell open -a RStudio "all-figures.R"
